<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>05_改变原数组的7个方法</title>
</head>

<body>
    <script>
        /*  push()/unshift() 头部添加/头部删除
    pop()/shift()  尾部添加/尾部删除

    splice(index,deCount,addElement...)
    
    reverse()反转数组

    sort() 排序  无序变有序 会改变原数组
     数组对象.sort((x,y)=> x-y) 从小到大排
     数组对象.sort((x,y)=> y-x) 从大到小 
*/

        let nums = [45, 17, 28, 3, 9]
        nums.sort((a, b) => (a - b)) //从小到大排  
        //console.log(nums.reverse());


        nums.sort((a, b) => (b - a))
        console.log(nums); // 从大到小


        let list = [{
                id: 9,
                price: 18.8,
                name: 'basketball'
            },
            {
                id: 21,
                price: 55.8,
                name: 'tennis ball'
            },
            {
                id: 55,
                price: 799.59,
                name: 'football'
            },
            {
                id: 87,
                price: 87.99,
                name: 'shuttle ball'
            },
        ]
        list.sort((obj1, obj2) => obj1.price - obj2.price) //从低到高
        console.log(list);

    //    list2 = list.sort((id1,id2)=>(id1.id-id2.id)) 
    //    console.log(list2);
    </script>
</body>

</html>